//引入数据库
const mysql = require('mysql')
//链接
const mysqlconfig = require('../../config/config.default')
//创建
const connection = mysql.createConnection(mysqlconfig.mysqlconfig)
//判断
connection.connect(function(err){
    if(err){
        return console.error(err)
    }else {
        console.log('mysql success');
    }
});

const query = (sql) =>{
    return new Promise((resolve, reject) => {
        connection.query(sql, function (error, results, fields) {
            if (error){
                reject(error)
                return
            } 
            resolve(results)
        });
    })
}

//暴露query
module.exports = query